package com.pt.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pt.entity.UserDailyDownload;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Insert;
import java.time.LocalDate;

@Mapper
public interface UserDailyDownloadMapper extends BaseMapper<UserDailyDownload> {
    
    @Update("UPDATE user_daily_download SET download_count = download_count + 1, updated_time = NOW() " +
            "WHERE user_id = #{userId} AND download_date = #{date}")
    int incrementDownloadCount(@Param("userId") Long userId, @Param("date") LocalDate date);
    
    @Insert("INSERT INTO user_daily_download (user_id, download_date, download_count, created_time, updated_time) " +
            "VALUES (#{userId}, #{date}, 1, NOW(), NOW()) " +
            "ON DUPLICATE KEY UPDATE download_count = download_count + 1, updated_time = NOW()")
    int insertOrIncrementDownloadCount(@Param("userId") Long userId, @Param("date") LocalDate date);
} 